<?php
/**
* Corrects the flags of the images under an album
*/

$image = new images();

$album_id = $variable->get('id', 'integer', 0); # Entity ID
$code = $variable->get('code', 'string', ''); # Protection Code

# Load all images (without caring the flags)
$sql="SELECT image_id FROM gallery_images_albums WHERE album_id={$album_id} AND is_active='Y' AND is_approved='Y' LIMIT 100;";
$db->query($sql);
$images = $db->to_columnar_array('image_id');
#print_r($images); die;

$album = new albums();
$album_details = $album->details($album_id);
#print_r($album_details);
#$album_path = $album_details[''];
/*
Array
(
    [album_id] => 8
    [subdomain_id] => 71
    [added_on] => 1326828121
    [fixed_on] => 0
    [modified_on] => 0
    [modified_counter] => 0
    [images_counter] => 10
    [sink_weight] => 0
    [is_active] => Y
    [is_approved] => N
    [album_name] => other-pics
    [album_folder] => F:/Desktop/other-pics
    [album_folder_local] => 
    [album_coverimage] => 
    [album_description] => 
    [code] => 087a1a1e66c0631d1a988101983923d4
)*/

$unapproved=0;
foreach($images as $image_id)
{
	if($image->verify_image($image_id, $album_details))
	{
		++$unapproved;
	}
}
if($unapproved)
{
	$messenger = new messenger('error', "Unapproved {$unapproved} images.");
}
else
{
	$messenger = new messenger('notice', "Nothing happened.");
}

$update_album_images_counter_sql="
UPDATE gallery_albums SET
	images_counter = (
		SELECT COUNT(*) FROM gallery_images_albums
		WHERE
			album_id={$album_id}
			AND is_active='Y'
			AND is_approved='Y'
	)
WHERE album_id={$album_id};";
#die($update_album_images_counter_sql);
$album->query($update_album_images_counter_sql);

# This is a controller only page and does not have anything to display.
headers::back('albums-list.php');
?>